package com.real.fact.web.customer.application;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.real.fact.web.application.AbstractPagedListCommand;
import com.real.fact.web.customer.domain.Customer;
import com.real.fact.web.customer.domain.CustomerFields;
import com.real.fact.web.customer.domain.CustomerRepository;
import com.real.fact.web.product.domain.ProductFilter;

public class ListCustomersCommand extends AbstractPagedListCommand<Customer> {

  private final CustomerRepository customerRepository;
  
  private Map<String, String> searchFields;
  
  private String searchFieldSelected = CustomerFields.NAME.toString().toLowerCase();
  
  private boolean activeChecked = true;

  private String field = "";

  public ListCustomersCommand(final CustomerRepository customerRepository) {
    super();
    this.customerRepository = customerRepository;
    searchFields = new HashMap<String, String>(); 
    searchFields.put(CustomerFields.NAME.toString(), "Nombre");
    searchFields.put(CustomerFields.CUIT.toString(), "Cuit");
  }

  public List<Customer> execute() {
    ProductFilter filter = new ProductFilter(activeChecked, searchFieldSelected, field);
    return customerRepository.filter(getPaging(), filter);
  }

  public Map<String, String> getSearchFields() {
    return searchFields;
  }

  public void setSearchFields(Map<String, String> searchFields) {
    this.searchFields = searchFields;
  }

  public String getSearchFieldSelected() {
    return searchFieldSelected;
  }

  public void setSearchFieldSelected(String searchFieldSelected) {
    this.searchFieldSelected = searchFieldSelected;
  }

  public boolean isActiveChecked() {
    return activeChecked;
  }

  public void setActiveChecked(boolean activeChecked) {
    this.activeChecked = activeChecked;
  }

  public String getField() {
    return field;
  }

  public void setField(String field) {
    this.field = field;
  }

}
